<template>
    <view @click="closeChildren" class="backMainType" hover-class="hover-view" custom-class="transition"
        :hover-stay-time="200">
        <text>萌虎壁纸</text>
        <image v-show='showChildren' :src="back" />
    </view>
    <view class="mainType">
        <view class="wallpaper" v-show='!showChildren'>
            <view class="item" v-for="(item, index) in mohuTypes" :key="index" @click="getChildren(item.children)">
                <text> {{ item.label }} </text>
                <image :src="bgList[bgList.length - 1 - index]" mode="aspectFill" />
            </view>
        </view>
        <view class="mohuTypes" v-show='showChildren'>
            <view class="childrenBox">
                <view hover-class="hover-view" custom-class="transition" :hover-stay-time="200" class="childrenItem"
                    v-for="(item, index) in mouhChildrenTypes" :key="index" @click="goMohu(item)">
                    {{ item.label }}
                </view>
            </view>
        </view>
    </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { mohuTypes } from './mohuTypes'
import back from '@/static/images/back.png'
defineProps({
    bgList: {
        type: Array as any,
        default: []
    }
})
const showChildren = ref(false)
const mouhChildrenTypes: any = ref([])
const getChildren = (item: any) => {
    mouhChildrenTypes.value = item
    showChildren.value = true
}
const closeChildren = () => {
    mouhChildrenTypes.value = []
    showChildren.value = false
}
const goMohu = (item: any) => {
    uni.navigateTo({
        url: `/pages/mohu/mohu?id=${item.value}&title=${item.label}`
    })
}
</script>

<style scoped lang="scss">
.backMainType {
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    font-size: 20px;
    font-weight: bold;
    margin: 20px 5rpx 10px 5rpx;
    padding: 10rpx;
    border-left: 4px solid #009dff;
    box-shadow: 0.3em 0.3em 0.7em var(--shadow);
    transition: border 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);

    image {
        width: 20px;
        height: 20px;
    }
}


.mainType {
    height: 320px;
    overflow-y: auto;
    box-shadow: 0.3em 0.3em 0.7em var(--shadow);
    transition: border 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);

    .mohuTypes {
        .childrenBox {
            padding: 5px;
            display: grid;
            grid-template-columns: 1fr 1fr;
            grid-gap: 10px;

            .childrenItem {
                padding: 10px 15px;
                box-shadow: 0em 0em 0.7em var(--shadow);
                transition: border 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                border-bottom: 1px solid var(--borderColor);
                border-radius: 20px;
            }
        }
    }
}
</style>